package com.ytjj.qmyx.mall.controller;

import com.alibaba.fastjson.JSON;
import com.ytjj.common.utils.HttpClientUtil;
import com.ytjj.qmyx.mall.utils.MD5Utils;
import org.apache.commons.codec.digest.DigestUtils;

import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

public class AliyunTest {

    public static void main(String[] args) {

        String URL = "https://o.csbdigit.com";
        String testUrl = "https://test-order-api.csbkk.com";

        String orderNo = "B434321";
        String key = "123456";
        String createTimeString = "2024-03-22 12:01:10";

        // 定义日期时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        // 将字符串解析为 LocalDateTime 对象
        LocalDateTime localDateTime = LocalDateTime.parse(createTimeString, formatter);

        // 将 LocalDateTime 转换为 ZonedDateTime，使用系统默认时区
        ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai"));

        // 获取毫秒级时间戳
        long orderTimeMillis = zonedDateTime.toInstant().toEpochMilli();
        String orderTime = String.valueOf(orderTimeMillis);
        System.out.println("orderTimeMillis:"+orderTime);

        Map<String,String> map = new HashMap<>();
        map.put("batchName","11");
        map.put("channelCode","qw-tt-01");
//        map.put("orderTime",orderTimeString);
//        map.put("province","广东");
        map.put("operationNode","1");
//        map.put("orderNo",orderNo);
        map.put("phone","17388888888");
//        map.put("paymentAmount","55");
//        map.put("name","测试");
        map.put("createTime",createTimeString);
        map.put("token","1234");

        String sign = null;
        try {
            sign = DigestUtils.md5Hex(key+orderTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map<String, String> heads = new HashMap<>();
        heads.put("sign",sign);
        String result = HttpClientUtil.doPostJson(testUrl+"/api/callback/ecommerce/pv", JSON.toJSONString(map),heads);
        System.out.println("结果:"+result);
    }
}
